#-*- coding:utf-8 -*-
from bluepy import btle

#运行此脚本，会使leamn震动
'''
def getInfo(addr, addrType):
    # if properties=='READ', readType and readMsg
    info = {}  # {service1:{chara1:[handle, properties, readType, readMsg], chara2}}
    try:
        d = btle.Peripheral(addr, addrType)
    except:
        print 'connect failed......'
        return 1
    try:
        for ser in d.getServices():
            dict1 = {}
            for chara in ser.getCharacteristics():
                list1 = []
                list1.append(str(chara.getHandle()))
                list1.append(chara.propertiesToString())
                if (chara.supportsRead()):
                    list1.append(type(chara.read()))
                    list1.append(chara.read())
                dict1[str(chara)] = list1
            info[str(ser)] = dict1
    except:
        print 'connect ended......'
        return 2
    d.disconnect()
    return info
'''
if __name__ == '__main__':
    addr = 'f5:26:9d:21:a7:fe'
    addrType = 'random'
    d = btle.Peripheral(addr, addrType)
    print d.writeCharacteristic(14, '\x7e\x05\x08\x01\x82', withResponse=True)
    '''
    addr = 'f5:26:9d:21:a7:fe'
    addrType = 'random'
    handle = 14
    fuzz_times = 100

    h = binarymuta.Handler()
    d = btle.Peripheral(addr, addrType)
    for i in range(0, fuzz_times):
        print d.writeCharacteristic(handle, h.Fuzzit('\x08\x00\xc4\x30\xd2\x39\xcc\x26\x00\x00'), withResponse=False)
    '''